package com.wuzhipeng.heart.user.convention.exceptionHandle;


import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.wuzhipeng.heart.user.convention.errorcode.BaseErrorCode;
import com.wuzhipeng.heart.user.convention.exception.ClientException;
import com.wuzhipeng.heart.user.convention.result.Result;
import com.wuzhipeng.heart.user.convention.result.Results;
import jakarta.servlet.http.HttpServletRequest;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.Optional;

/**
 * 全局异常处理器
 *
 */
@Component
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    /**
     * 拦截应用内抛出的异常
     */
    @ExceptionHandler(value = ClientException.class)
    public Result abstractException(HttpServletRequest request,ClientException ex) {
        return Results.failure(ex.getErrorCode(), ex.getErrorMessage());
    }


}